//
//  XLPersonCenterHeader.m
//  XLPersonCenter
//
//  Created by 宋振 on 2018/7/19.
//  Copyright © 2018年 夜幕繁华. All rights reserved.
//

#import "XLPersonCenterHeader.h"

#import "Masonry.h"
#import "XLPersonCenterTool.h"
#import "XLRecordTool.h"

#import "UIButton+OperatingInternalSpace.h"

//轮播图高度
#define kCycleHeight 387

@interface XLPersonCenterHeader ()<SDCycleScrollViewDelegate,XLRecorderToolDelegate>

//接通率
@property (nonatomic, strong) UILabel *  iphoneLbl;

//视频价格
@property (nonatomic, strong) UILabel *  videoPriceLbl;

//语音价格
@property (nonatomic, strong) UILabel *  voicePriceLbl;

//标签价格
@property (nonatomic, strong) UILabel *  priceLbl;

//性别 年龄
@property (nonatomic, strong) UIButton *  authentication;

//ID
@property (nonatomic, strong) UILabel *  XLIdLbl;

//等级
//@property (nonatomic, strong) UIImageView *  levelLbl;

//语音
@property (nonatomic, strong) UIButton *  autoClick;

//是否在线
@property (nonatomic, strong) UIView *  OnLine;

//是否在线：文字描述
@property (nonatomic, strong) UILabel *  onLineLbl;


@end

@implementation XLPersonCenterHeader
{
    //语音动画容器
    UIImageView *autoImageView;
    
    //视频标志
    UIImageView *videoImgView;
    
    //语音标志
    UIImageView *voiceImgView;
    
    //动画是否正在执行
    BOOL isSpeech;
    
    //保存语音路径
    NSString *playUrl;
    
    //语音时长
    NSInteger playCost;
    
    //在线背景容器
    UIView *onLineView;
}

//修饰
@synthesize nickName = _nickName;

- (instancetype)init
{
    self = [super init];
    
    if (self) {
        
        /**
         加载主要视图
         */
        [self setCustomeView];
        
    }
    
    return self;
}

#pragma mark    -   -   - 绘制界面显示 - - -

/**
 主要界面显示： 轮播图 昵称 各种标签等
 */
- (void)setCustomeView
{
    //初始化 辅助变量等
    [self initToolSource];
    
    //轮播图
    [self layOutCycleView];
    
    //分段选择
    [self layOutSegementView];
    
    //其他控件
    [self layOutOther];
}

/**
 初始化 辅助变量等
 */
- (void)initToolSource
{
    isSpeech = NO;
}

/**
 轮播图
 */
- (void)layOutCycleView
{
    self.cycleScrollView = [[SDCycleScrollView alloc] init];
    self.cycleScrollView.translatesAutoresizingMaskIntoConstraints = NO;
    self.cycleScrollView.delegate = self;
    
    //设置本地图片
//    self.cycleScrollView.localizationImageNamesGroup = @[@"1"];
    self.cycleScrollView.backgroundColor = [UIColor whiteColor];
    
    //轮播page颜色
    self.cycleScrollView.pageDotColor = [UIColor lightGrayColor];
    
    //间隔时间(默认两秒)
    self.cycleScrollView.autoScrollTimeInterval = 2.0f;
    
    //是否无限循环
    self.cycleScrollView.infiniteLoop = YES;
    
    //是否在只有一张图时隐藏page显示
    self.cycleScrollView.hidesForSinglePage = YES;
    
    //分页控件显示
    self.cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    
    [self addSubview:self.cycleScrollView];
    
    //约束
    [self.cycleScrollView.topAnchor constraintEqualToAnchor:self.topAnchor].active = YES;
    [self.cycleScrollView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor].active = YES;
    [self.cycleScrollView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor].active = YES;
    [self.cycleScrollView.heightAnchor constraintEqualToConstant:kCycleHeight].active = YES;

}

/**
 分段选择
 */
- (void)layOutSegementView
{
    self.segmentView = [[XLPersonCenterSegmented alloc] init];

    self.segmentView.translatesAutoresizingMaskIntoConstraints = NO;

    [self addSubview:self.segmentView];

    //约束

    [self.segmentView.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
    [self.segmentView.topAnchor constraintEqualToAnchor:self.cycleScrollView.bottomAnchor].active = YES;
    [self.segmentView.widthAnchor constraintEqualToAnchor:self.widthAnchor].active = YES;
    [self.segmentView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor].active = YES;
}

/**
 其他子视图：昵称，接通率，价格/每分钟，语音播放按钮
 */
- (void)layOutOther
{
    
    /**
     昵称
     */
    _nickName = [[UILabel alloc] init];
    
    //修饰
    _nickName.text = @"";
    
    _nickName.textColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1];
    _nickName.font = [UIFont fontWithName:kFontNamePFRegular size:kNickNameFontSize];
    _nickName.textAlignment = NSTextAlignmentLeft;
    
    [self addSubview:_nickName];
    
    //约束
    [_nickName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kNickNameLeftSpace);
        make.top.equalTo(self.mas_top).offset(kNickNameTopSpace);
        make.height.mas_equalTo(kNickNameHeight);
    }];
    
    /**
     语音按钮
     */
    self.autoClick = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self addSubview:self.autoClick];
    
    
    //修饰
    self.autoClick.layer.cornerRadius = 14;
    self.autoClick.layer.masksToBounds = YES;
    self.autoClick.backgroundColor = RGB(255, 187, 1);
    
    [self.autoClick setImage:[UIImage imageNamed:@"common_dx_yuyin3_n"] forState:(UIControlStateNormal)];
    [self.autoClick setAttributedTitle:[self layOutSpeechSecondText:@"0’"] forState:(UIControlStateNormal)];
    
    [self.autoClick addTarget:self action:@selector(clickSpeech:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //约束
    [self.autoClick mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nickName.mas_right).offset(10);
        make.centerY.equalTo(self.nickName.mas_centerY);
//        make.right.equalTo(self.mas_right).offset(-kAutoClickSpaceRight);
//        make.bottom.equalTo(self.mas_bottom).offset(-65);
        make.width.mas_equalTo(kAutoClickWidth);
        make.height.mas_equalTo(kAutoClickHeight);
    }];
    
    //语音动画容器
    [self autoClickImageView];
    
    //下划线标志
    UIView *lineView = [[UIView alloc] init];
    [self addSubview:lineView];
    
    //修饰 
    lineView.backgroundColor = [UIColor whiteColor];
    lineView.alpha = 0.4;
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nickName.mas_left);
        make.bottom.equalTo(self.segmentView.mas_top).offset(-55);
        make.width.mas_equalTo(kScale(183));
        make.height.mas_equalTo(kScale(1));
    }];
    
    /**
     在线状态
     */
    [self setOnLineStatusUI];
    
    
    /**
     性别年龄 主播/用户等级
     */
    [self layOutAgeAndLevel];
    
}

/**
 性别年龄 主播/用户等级
 */
- (void)layOutAgeAndLevel
{
    /**
     心聊ID
     */
    self.XLIdLbl = [[UILabel alloc] init];
    self.XLIdLbl.backgroundColor = RGB(56, 172, 255);
    self.XLIdLbl.textColor = RGB(255, 255, 255);
    self.XLIdLbl.font = [UIFont fontWithName:kFontNamePFRegular size:11];
    self.XLIdLbl.layer.cornerRadius = 8;
    self.XLIdLbl.layer.masksToBounds = YES;
    self.XLIdLbl.text = @"ID";
    self.XLIdLbl.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.XLIdLbl];
    
    [self.XLIdLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nickName.mas_left);
        make.bottom.equalTo(self.cycleScrollView.mas_bottom).offset(-kAgeGenderSpaceBottom);
        make.width.mas_equalTo(kAgeGenderWidth);
        make.height.mas_equalTo(kAgeGenderHeight);
    }];
    
    /**
     接通率
     */
    self.iphoneLbl = [[UILabel alloc] init];
    self.iphoneLbl.backgroundColor = RGB(255, 140, 205);
    self.iphoneLbl.textColor = RGB(255, 255, 255);
    self.iphoneLbl.font = [UIFont fontWithName:kFontNamePFRegular size:10];
    self.iphoneLbl.layer.cornerRadius = 8;
    self.iphoneLbl.layer.masksToBounds = YES;
    self.iphoneLbl.text = @"接通率 0 %";
    self.iphoneLbl.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.iphoneLbl];
    
    [self.iphoneLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.XLIdLbl.mas_right).offset(kScale(9));
        make.bottom.equalTo(self.cycleScrollView.mas_bottom).offset(-kAgeGenderSpaceBottom);
        make.width.mas_equalTo(kAgeGenderWidth);
        make.height.mas_equalTo(kAgeGenderHeight);
    }];
    
    
    //性别和年龄
    self.authentication = [UIButton buttonWithType:(UIButtonTypeCustom)];
    
    [self setLabelInsetMakeLeftImageAndRightLabel:self.authentication];
    self.authentication.hidden = YES;
    [self addSubview:self.authentication];
    
    //约束
    [self.authentication mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iphoneLbl.mas_right).offset(kScale(7));
        make.bottom.equalTo(self.cycleScrollView.mas_bottom).offset(-kAgeGenderSpaceBottom);
        make.width.mas_equalTo(38);
        make.height.mas_equalTo(kAgeGenderHeight);
    }];
    
    //修饰
    self.authentication.backgroundColor = RGB(255, 102, 153);
    
    [self.authentication setLabelViewWithButton:self.authentication title:@"女神" image:@"common_icon_rzns_n" fontName:kFontNamePFRegular fontSize:kLabelFontSize cornerRadius:kLabelRadius];
    
    [self.authentication addTarget:self action:@selector(clickAgeGenderAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    
    // 主播/用户等级
//    self.levelLbl = [[UIImageView alloc] init];
//
//    self.levelLbl.image = [[UIImage imageNamed:@"me_grade_icons_yh15"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
//
//    [self addSubview:self.levelLbl];
//
//    //约束
//    [self.levelLbl mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(self.authentication.mas_centerY);
//        make.left.equalTo(self.authentication.mas_right).offset(kLevelSpaceLeft);
//        make.width.height.equalTo(self.authentication);
//    }];
    
    

}

/**
 在线状态 和 关注按钮
 */
- (void)setOnLineStatusUI
{
    //设置在线背景容器
    onLineView = [[UIView alloc] init];
    
    onLineView.backgroundColor = RGBA(0, 0, 0, 0.3);
    
    onLineView.layer.cornerRadius = 3;
    onLineView.hidden = YES;
    onLineView.layer.masksToBounds = YES;
    
    [self addSubview:onLineView];
    
    [onLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_nickName.mas_centerY);
        make.right.equalTo(self.mas_right).offset(-15);
        make.width.mas_equalTo(kScale(40));
        make.height.mas_equalTo(18);
    }];
    
    //设置状态
    self.OnLine = [[UIView alloc] init];
    self.OnLine.backgroundColor = RGB(66, 197, 112);
    self.OnLine.layer.cornerRadius = 2.5;
    self.OnLine.layer.masksToBounds = YES;
    [onLineView addSubview:self.OnLine];
    
    [self.OnLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(onLineView.mas_centerY);
        make.left.equalTo(onLineView.mas_left).offset(kScale(5));
        make.size.mas_equalTo(CGSizeMake(5, 5));
    }];
    
    self.onLineLbl = [[UILabel alloc] init];
    self.onLineLbl.textAlignment = NSTextAlignmentLeft;
    self.onLineLbl.attributedText = [self setOnlineLabelAttributeWithString:@"在线"];
    [onLineView addSubview:self.onLineLbl];
    
    [self.onLineLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(onLineView.mas_centerY);
        make.left.equalTo(self.OnLine.mas_right).offset(kScale(3));
        make.size.mas_equalTo(CGSizeMake(22, 14));
    }];
    
    
    self.attentionBt = [[UIButton alloc] init];
    self.attentionBt.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 4);
    self.attentionBt.titleEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 0);
    
    //修饰
    self.attentionBt.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.attentionBt setTitle:@"关注Ta" forState:UIControlStateNormal];
    [self.attentionBt setTitleColor:KWhiteColor forState:(UIControlStateNormal)];
    [self.attentionBt setImage:[UIImage imageNamed:@"common_icon_guanzhu_n"] forState:(UIControlStateNormal)];
    self.attentionBt.backgroundColor = RGBA(0, 0, 0, 0.3);
    [self.attentionBt addTarget:self action:@selector(followAction) forControlEvents:(UIControlEventTouchUpInside)];
    self.attentionBt.layer.cornerRadius = 4;
    self.attentionBt.layer.masksToBounds = YES;
    [self addSubview:self.attentionBt];
    
    [self.attentionBt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(82, 32));
        make.right.equalTo(self.mas_right).offset(-13);
        make.top.equalTo(onLineView.mas_bottom).offset(9);
    }];
    
    
}

#pragma mark -- 关注点击事件
-(void)followAction
{
    if(self.followClickBlock)
    {
        self.followClickBlock();
    }
}

- (void)setPriceStatus
{
    /**
     视频价格
     */
    //视频标志
    videoImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"common_icon_vedio_n"]];
    [self addSubview:videoImgView];
    
    [videoImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nickName.mas_bottom).offset(7);
        make.left.equalTo(self.nickName.mas_left);
        make.size.mas_equalTo(CGSizeMake(16, 16));
    }];
    
    //视频价格显示
    self.videoPriceLbl = [[UILabel alloc] init];
    self.videoPriceLbl.textColor = RGB(255, 255, 255);
    self.videoPriceLbl.font = [UIFont fontWithName:kFontNamePFRegular size:12];
    [self addSubview:self.videoPriceLbl];
    
    [self.videoPriceLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(videoImgView.mas_centerY);
        make.left.equalTo(videoImgView.mas_right).offset(4);
        make.height.mas_equalTo(17);
    }];
    
    self.videoPriceLbl.attributedText = [self setAttributeWithString:@"0金豆/分钟"];
    
    /**
     语音价格
     */
    voiceImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"common_icon_voice_n"]];
    [self addSubview:voiceImgView];
    
    [voiceImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(videoImgView.mas_top);
        make.left.equalTo(self.videoPriceLbl.mas_right).offset(kScale(12));
        make.size.mas_equalTo(CGSizeMake(16, 16));
    }];
    
    //语音价格显示
    self.voicePriceLbl = [[UILabel alloc] init];
    self.voicePriceLbl.textColor = RGB(255, 255, 255);
    self.voicePriceLbl.font = [UIFont fontWithName:kFontNamePFRegular size:12];
    [self addSubview:self.voicePriceLbl];
    
    [self.voicePriceLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(voiceImgView.mas_centerY);
        make.left.equalTo(voiceImgView.mas_right).offset(4);
        make.height.mas_equalTo(17);
    }];
    
    self.voicePriceLbl.attributedText = [self setAttributeWithString:@"0金豆/分钟"];
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:XiangLove_IsSH] boolValue]) {//
        self.voicePriceLbl.hidden = YES;
        self.videoPriceLbl.hidden = YES;
        videoImgView.hidden = YES;
        voiceImgView.hidden = YES;
    }
}

- (void)setVoicePRiceShow
{
    /**
     语音价格
     */
    voiceImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"common_icon_voice_n"]];
    [self addSubview:voiceImgView];
    
    [voiceImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nickName.mas_bottom).offset(7);
        make.left.equalTo(self.nickName.mas_left);
        make.size.mas_equalTo(CGSizeMake(16, 16));
    }];
    
    //语音价格显示
    self.voicePriceLbl = [[UILabel alloc] init];
    self.voicePriceLbl.textColor = RGB(255, 255, 255);
    self.voicePriceLbl.font = [UIFont fontWithName:kFontNamePFRegular size:12];
    [self addSubview:self.voicePriceLbl];
    
    [self.voicePriceLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(voiceImgView.mas_centerY);
        make.left.equalTo(voiceImgView.mas_right).offset(4);
        make.height.mas_equalTo(17);
    }];
    
    self.voicePriceLbl.attributedText = [self setAttributeWithString:@"0金豆/分钟"];
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:XiangLove_IsSH] boolValue]) {//
        self.voicePriceLbl.hidden = YES;
        voiceImgView.hidden = YES;
    }
}

#pragma mark    - - - Button Action - - -
/**
 点击语音事件
 */
- (void)clickSpeech:(UIButton *)sender
{
    
    
    //判断当前动画是否正在执行
    if (isSpeech) {
        
        //如果语音没有播放 那么停止动画
        if ([[XLRecordTool shareRecordTool].player isPlaying]) {
            [[XLRecordTool shareRecordTool].player stop];
            
        }
        [self speechStop];
        
        return;
    }
    
    if (!playUrl) {
        NSLog(@"没有语音连接");
        return;
    }
    
    [XLRecordTool shareRecordTool].delegate = self;
    
    if (self.userInfoModel && self.userInfoModel.VoiceSignatures) {
        
        [XLRecordTool shareRecordTool].playUrl = K_DEFULT(playUrl);
        
    }
    
    //开始动画
    [self speechStart];
    
    NSInteger second = playCost;
    
    //临时延长时间
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(second * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

        //动画结束
        [self speechStop];
    });
}

/**
 点击标签事件
 */

//点击性别 年龄标签
- (void)clickAgeGenderAction:(UIButton *)sender
{
    NSLog(@"点击了性别年龄标签");
}

//点击等级标签
- (void)clickLevelAction:(UIButton *)sender
{
    NSLog(@"点击了等级标签");
}



#pragma mark    - - - Other Method - - -

/**
 语音动画开始 结束 事件
 */
- (void)speechStart
{
    [[XLRecordTool shareRecordTool] playRecord];
    isSpeech = YES;
    [self.autoClick.imageView startAnimating];
    [self.autoClick setImage:[UIImage imageNamed:@"common_dx_yuyin1_n"] forState:(UIControlStateNormal)];
}
- (void)speechStop
{
    [[XLRecordTool shareRecordTool] stopRecord];
    
    isSpeech = NO;
    [self.autoClick.imageView stopAnimating];
    [self.autoClick setImage:[UIImage imageNamed:@"common_dx_yuyin3_n"] forState:(UIControlStateNormal)];
}

/**
 添加语音动画
 */
- (void)autoClickImageView
{
    
    //动画集
    NSArray *images = [NSArray arrayWithObjects:[UIImage imageNamed:@"common_dx_yuyin1_n"],[UIImage imageNamed:@"common_dx_yuyin2_n"],[UIImage imageNamed:@"common_dx_yuyin3_n"], nil];
    
    self.autoClick.imageView.animationImages = images;
    
    //设置动画集
    self.autoClick.imageView.animationImages = images;
    
    //时长
    self.autoClick.imageView.animationDuration = 1.0f;
    
    //重复动画
    self.autoClick.imageView.animationRepeatCount = 0;
    
}

/**
 标签显示设置:左图 右标题
 */
- (void)setLabelInsetMakeLeftImageAndRightLabel:(UIButton *)button
{
    [button setImageEdgeInsets:UIEdgeInsetsMake(kScale(3), kScale(4), kScale(3), kScale(14))];
    [button setTitleEdgeInsets:UIEdgeInsetsMake(kScale(3), kScale(4), kScale(3), kScale(0))];
}



#pragma mark    - - - SDCycleScrollViewDelegate - - -

/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    NSLog(@"点击轮播图片 第 %ld 张",index);
}

/** 图片滚动回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index
{
    NSLog(@"轮播图片滚动 第 %ld 张",index);
}

- (void)updateTime:(NSInteger)second
{
    if (second > playCost) {
        
        [[XLRecordTool shareRecordTool].player stop];
        
        [self speechStop];
    }
}


#pragma mark    -   -   - Setter -  -   -

//设置数据源
- (void)setUserInfoModel:(XLUserInfoDetailModel *)userInfoModel
{
    _userInfoModel = userInfoModel;
    
    if (!userInfoModel) {
        return;
    }
    
    self.cycleScrollView.imageURLStringsGroup = userInfoModel.Photos;
    
    //设置数据显示
    _nickName.text = userInfoModel.NickName;
    
    //ID
    self.XLIdLbl.text = [NSString stringWithFormat:@"ID %@",userInfoModel.UserId];
    
    //接通率
    self.iphoneLbl.text = [NSString stringWithFormat:@"接通率 %@ %%",userInfoModel.ConnectRate];
    
    //主播认证
    if (userInfoModel.IsAnchor) {
        
        //更新UI显示
        [self setPriceStatus];
        
        self.authentication.hidden = NO;
        
        self.videoPriceLbl.text = [NSString stringWithFormat:@"%.lf金豆/分钟",userInfoModel.LiveChatPrice.doubleValue*10];
        
        if (userInfoModel.Sex.integerValue == 0) {
            self.authentication.backgroundColor = RGB(95, 189, 255);
            
            [self.authentication setAttributedTitle:[self setButtonTitleWithString:@"男神"] forState:(UIControlStateNormal)];
        }else{
            self.authentication.backgroundColor = RGB(255, 102, 153);
            [self.authentication setAttributedTitle:[self setButtonTitleWithString:@"女神"] forState:(UIControlStateNormal)];
        }
        BOOL isSelf = [[NSString stringWithFormat:@"%@",userInfoModel.UserId] isEqualToString:[[XLAccountManager shareInstance] model].Id];
        if (isSelf) {
            self.attentionBt.hidden = YES;
        }else{
            if (userInfoModel.IsAttention) {
                self.attentionBt.hidden = YES;
            }else{
                self.attentionBt.hidden = NO;
            }
        }
        
    }else{
        [self setVoicePRiceShow];
        self.iphoneLbl.hidden = YES;
        self.authentication.hidden = YES;
        BOOL isSelf = [[NSString stringWithFormat:@"%@",userInfoModel.UserId] isEqualToString:[[XLAccountManager shareInstance] model].Id];
        
        if (isSelf) {
            self.attentionBt.hidden = YES;
        }else{
            if (userInfoModel.IsAttention) {
                self.attentionBt.hidden = YES;
            }else{
                self.attentionBt.hidden = NO;
            }
        }
    }
    
    self.voicePriceLbl.text = [NSString stringWithFormat:@"%.lf金豆/分钟",userInfoModel.SoundChatPrice*10];
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:XiangLove_IsSH] boolValue]) {//
        self.voicePriceLbl.hidden = YES;
        self.videoPriceLbl.hidden = YES;
        
    }
    
    //设置是否现在 3在线 2忙碌 其他离线
    if ([userInfoModel.OnlineStatus isEqualToString:@"3"]) {
        onLineView.hidden = NO;
        self.OnLine.backgroundColor = RGB(66, 197, 172);
        self.onLineLbl.attributedText = [self setOnlineLabelAttributeWithString:@"在线"];
        
    }else if ([userInfoModel.OnlineStatus isEqualToString:@"2"]){
        onLineView.hidden = NO;
        self.OnLine.backgroundColor = RGB(244, 76, 76);
        self.onLineLbl.attributedText = [self setOnlineLabelAttributeWithString:@"忙碌"];
    }else{
        
        self.OnLine.backgroundColor = RGB(102, 102, 102);
        self.onLineLbl.attributedText = [self setOnlineLabelAttributeWithString:@"离线"];
        onLineView.hidden = YES;
        
    }
    
    BOOL isSelf = [[NSString stringWithFormat:@"%@",userInfoModel.UserId] isEqualToString:[[XLAccountManager shareInstance] model].Id];
    if(isSelf || userInfoModel == nil)
    {
        onLineView.hidden = NO;
        self.OnLine.backgroundColor = RGB(66, 197, 172);
        self.onLineLbl.attributedText = [self setOnlineLabelAttributeWithString:@"在线"];
    }
    
    if (userInfoModel.VoiceSignatureList.count > 0) {
        
        self.autoClick.hidden = NO;
        
        NSArray *speechModels = userInfoModel.VoiceSignatureList;
        
        NSDictionary *dic = speechModels[0];
        
        NSString *playcost = [NSString stringWithFormat:@"%@",dic[@"PlayCost"]];
        playCost = playcost.integerValue;
        playUrl = K_DEFULT(dic[@"PlayUrl"]);
        
        [self.autoClick setAttributedTitle:[self layOutSpeechSecondText:playcost] forState:(UIControlStateNormal)];
        
    }else{
        self.autoClick.hidden = YES;
    }
    
}

//Tools
- (NSMutableAttributedString *)setAttributeWithString:(NSString *)string
{
    NSMutableDictionary *iphoneDic = [NSMutableDictionary dictionary];
    [iphoneDic setValue:@1 forKey:NSKernAttributeName];
    
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:string attributes:iphoneDic];
    
    return attribute;
}

- (NSAttributedString *)setButtonTitleWithString:(NSString *)string
{
    NSDictionary *attributes = @{
                                 NSFontAttributeName:[UIFont fontWithName:kFontNamePFRegular size:kLabelFontSize],
                                 NSForegroundColorAttributeName:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1]
                                 };
    
    NSAttributedString *attribute = [[NSAttributedString alloc] initWithString:string attributes:attributes];
    
    return attribute;
}

- (NSAttributedString *)setOnlineLabelAttributeWithString:(NSString *)text
{
    NSAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:text attributes:@{NSKernAttributeName:@1,NSForegroundColorAttributeName:RGB(255, 255, 255),
                                                                                                         NSFontAttributeName:[UIFont fontWithName:kFontNamePFRegular size:10]
                                                                                                         }];
    
    return attribute;
}

/**
 设置语音读秒字体
 */
- (NSAttributedString *)layOutSpeechSecondText:(NSString *)text
{
    NSDictionary *dic = @{
                          NSKernAttributeName:@1,
                          NSForegroundColorAttributeName:RGB(255, 255, 255),
                          NSFontAttributeName:[UIFont fontWithName:KFontNamePFMedium size:12]
                          };
    
    NSAttributedString *attribute = [[NSAttributedString alloc] initWithString:text attributes:dic];
    
    return attribute;
}



@end
